using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;

namespace LogParser.Collections
{
    public class WeaponList
    {
        #region Private Member Variables

        private DA.WeaponListModel _model;

        private Hashtable _weaponList;

        #endregion

        #region Public Member Variables

        #endregion

        #region Constructor

        public WeaponList()
        {
            Initialize();
        }

        /// <summary>
        /// Initialize method
        /// </summary>
        private void Initialize()
        {
            _model = new LogParser.DA.WeaponListModel();
            _weaponList = new Hashtable();

            List<GameObjects.Weapon> weaponList = _model.GetWeaponsList();

            foreach ( GameObjects.Weapon tempWeapon in weaponList )
            {
                _weaponList.Add( tempWeapon.Name, tempWeapon );
            }

        }

        #endregion

        #region Public Properties

        /// <summary>
        /// Public accessor for the number of weapons returned from the database
        /// </summary>
        public int Count
        {
            get
            {
                return _weaponList.Count;
            }
        }


        #endregion

        #region Private Properties
        #endregion

        #region Public Methods

        /// <summary>
        /// Gets a weapon from the weapon list based on the weapon name passed in
        /// </summary>
        /// <param name="WeaponName">The log file "weapon name" to be looked up</param>
        /// <returns>GameObjects.Weapon object corresponding to the WeaponName passed in</returns>
        public GameObjects.Weapon GetWeapon( string WeaponName )
        {
            GameObjects.Weapon returnWeapon = new GameObjects.Weapon();
            try
            {
                returnWeapon = (GameObjects.Weapon) ( _weaponList[ WeaponName ] );
            }
            catch
            {

            }

            return returnWeapon;
        }

        /// <summary>
        /// Gets a weapon from the weapon list based on the weapon name passed in
        /// </summary>
        /// <param name="WeaponName">The log file "weapon name" to be looked up</param>
        /// <returns>GameObjects.Weapon object corresponding to the WeaponName passed in</returns>
        public GameObjects.Weapon GetWeapon( int weaponId )
        {
            GameObjects.Weapon returnWeapon = new GameObjects.Weapon();
            try
            {
                foreach ( DictionaryEntry de in _weaponList )
                {

                    GameObjects.Weapon weapon = ( (GameObjects.Weapon) de.Value );
                    if ( weapon.WeaponID == weaponId )
                        returnWeapon = weapon;
                        break;
                }
            }
            catch
            {

            }

            return returnWeapon;
        }

        /// <summary>
        /// Gets an instance of the weapon list
        /// </summary>
        /// <returns></returns>
        public Hashtable GetWeaponList()
        {
            return _weaponList;
        }

        #endregion

        #region Private Methods
        #endregion


    }
}
